package com.zl.test.restdemo.exception;

import com.zl.test.restdemo.common.utils.ResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author: zhang lei
 * @Describe: All things are difficult before they are easy.
 * @CreatTime: 2021-02-24-16-36
 */
@ControllerAdvice
@ResponseBody
@Slf4j
public class ExceptionHandleAdvice<T> {
    @ExceptionHandler(Exception.class)
    public ResponseEntity<String> handleException(Exception e) {
        log.error("请求异常,异常信息为:message : {}, exc = {}",e.getMessage(),e);
        if(e instanceof DemoServiceException){
            return ResponseEntity.failure((DemoServiceException)e);
        }else{
            return ResponseEntity.failure("系统异常，稍后再试!", 99999);
        }

    }
}
